<%@page contentType="text/html;charset=UTF-8" import="
    movies.Movies,
    javax.jcr.Node,
    java.util.Iterator,
    org.apache.sling.api.resource.Resource,
    org.apache.sling.api.resource.ValueMap"
%><%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"%><%
%><sling:defineObjects/><%

ValueMap properties     = resource.adaptTo(ValueMap.class);
Resource rootResource   = Movies.getRoot(resource);
ValueMap rootProperties = rootResource.adaptTo(ValueMap.class);

%><!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title><%= properties.get("title", "") %></title>
        <link rel="stylesheet" type="text/css" href="/etc/designs/movies/style.css" />
    </head>
    
    <body class="page-movie">
        <h1><a href="<%= rootResource.getPath() %>.html"><%= rootProperties.get("title", "") %></a></h1>
    
        <article class="movie">
            <img class="movie-poster" src="<%= properties.get("poster", "") %>" alt="<%= properties.get("title", "") %>" />
            
            <h2 class="movie-title"><%= properties.get("title", "") %></h2>
            
            <section class="movie-year">
                <h3>Year</h3>
                <p><%= properties.get("year", "") %></p>
            </section>
            
            <section class="movie-runtime">
                <h3>Runtime</h3>
                <p><%= properties.get("runtime", "") %></p>
            </section>
            
            <section class="movie-cast">
                <h3>Cast</h3>
                <% String[] cast = properties.get("cast", String[].class); %>
                <ul class="movie-cast-list">
                    <% for (String actor : cast) { %>
                        <li class="movie-cast-item"><%= actor %></li>
                    <% } %>
                </ul>
            </section>
            
            <section class="movie-synopsis">
                <h3>Synopsis</h3>
                <p><%= properties.get("synopsis", "") %></p>
            </section>
            
            <section class="movie-comments">
                <h3>Comments</h3>
                
                <% Iterator<Resource> children = resource.listChildren(); %>
                <% while (children.hasNext()) { %>
                    <sling:include resource="<%= children.next() %>" />
                <% } %>
                
                <form method="post" action="<%= resource.getPath() %>.html" enctype="multipart/form-data" class="form-comment">
                    <p>
                        <label for="input-name">Your Name</label>
                        <input type="text" name="name" id="input-name" />
                    </p>
                    <p>
                        <label for="input-email">Your Email</label>
                        <input type="text" name="email" id="input-email" />
                    </p>
                    <p>
                        <label for="input-content">Your Comment</label>
                        <textarea name="content" id="input-content"></textarea>
                    </p>
                    <p>
                        <input type="hidden" name="_charset_" value="UTF-8"/>
                        <input type="submit" value="Submit Comment" />
                    </p>
                </form>
            </section>
        </article>
    </body>
</html>
<% out.flush(); %>
